package com.ghc.aop;

//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpSession;

import org.aspectj.lang.JoinPoint;

import com.ghc.pojo.User;
import com.ghc.util.SysContent;

public class MethodLog {
	private static Logger logger = Logger.getLogger("UserOperateLog");
	public void gotLog(JoinPoint joinpoint){
		//HttpServletRequest request = SysContent.getRequest();  
        //HttpServletResponse response = SysContent.getResponse();  
        HttpSession session = SysContent.getSession();
        
        String userName = "";
        if(session==null){
        	userName = "anonymous";
        }else{
        	if(session.getAttribute("user")==null){
        		userName = "anonymous";
        	}else{
        		userName = (String) ((User) session.getAttribute("user")).getUsername();
        	}
        }
		String methodName = joinpoint.getSignature().getName();
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String date = (String) df.format(new Date());
		
		System.out.println("用户"+userName+"在"+date+"使用了"+methodName+"方法");
		logger.info(date+":用户"+userName+"使用了"+methodName+"方法");
	}

}
